package eerr.llrr.oorr.pte9983.uggtip9324

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.text.TextUtils
import eerr.llrr.oorr.pte9983.wifi4392.jump98001.RouteJump

class PgStateRv : BroadcastReceiver() {

    private var lastTime: Long = 0

    override fun onReceive(context: Context?, intent: Intent?) {
        when (intent?.action) {
            Intent.ACTION_PACKAGE_ADDED -> {
                var l = System.currentTimeMillis() - lastTime
                if (l > 0 && l < 5 * 60 * 1000) {
                    return
                }

                val data = intent.data

                if (data != null) {
                    val packageName = data.schemeSpecificPart
                    if (!TextUtils.isEmpty(packageName) && "com.p.b.wifimaster".equals(packageName)) {
                        return
                    }

                    RouteJump.safeJump(yyee.llee.mmee.pl190.host668.RouteKey.INSTALL)
                    lastTime = System.currentTimeMillis()

                }

            }

            Intent.ACTION_PACKAGE_REMOVED -> {
                val l = System.currentTimeMillis() - lastTime

                if (l > 0 && l < 5 * 60 * 1000) {
                    return
                }

                RouteJump.safeJump(yyee.llee.mmee.pl190.host668.RouteKey.UNINSTALL)

                lastTime = System.currentTimeMillis()
            }
        }
    }


    companion object {
        fun registerPackageReceiver(context: Context?) {
            try {

                val leActionReceiver = PgStateRv()
                val filter = IntentFilter()

                filter.addAction(Intent.ACTION_PACKAGE_ADDED)
                filter.addAction(Intent.ACTION_PACKAGE_REMOVED)
                filter.addDataScheme("package")

                filter.priority = IntentFilter.SYSTEM_HIGH_PRIORITY
                context?.registerReceiver(leActionReceiver, filter)

            } catch (e: Exception) {
                e.printStackTrace()
            }
        }
    }
}